va_arg: pass in TyAndLayout - #163021
Merged
Merged
va_arg: pass in TyAndLayout#163021
va_arg: pass in TyAndLayout#163021Conversation
folkertdev
marked this pull request as ready for review
September 19, 2026 17:02
Collaborator
|
r? @adwinwhite rustbot has assigned @adwinwhite. Use Why was this reviewer chosen?The reviewer was selected based on:
|
adwinwhite
reviewed
Sep 20, 2026
| bx: &mut Builder<'_, 'll, 'tcx>, | ||
| list: OperandRef<'tcx, &'ll Value>, | ||
| target_ty: Ty<'tcx>, | ||
| target_ty: TyAndLayout<'tcx>, |
Contributor
There was a problem hiding this comment.
Is target_ty -> layout clearer? And more consistent with the naming of TyAndLayout elsewhere.
Contributor
Author
There was a problem hiding this comment.
Sure, I did that rename
weird I did not spot this before, it cleans up the code a bunch
folkertdev
force-pushed
the
va-arg-ty-and-layout
branch
from
September 20, 2026 10:52
f720b76 to
d61037d
Compare
Contributor
|
@bors r+ rollup |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 20, 2026
…=adwinwhite `va_arg`: pass in `TyAndLayout` Just a refactor, no functional changes. It is weird I did not spot this before, it cleans up the code a bunch.
This was referenced Sep 20, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 20, 2026
…uwer Rollup of 15 pull requests Successful merges: - #162726 (std: fix unix socket address panic on a full sun_path) - #163016 (Don't claim that escaping value is a reference in diagnostics) - #163040 (Tweak "use array's length as const param" suggestion) - #163060 (Point to fields that introduce trait requirements) - #163066 (don't mark `f128` as reliable on AIX) - #162098 (Tweak `Infallible` docs) - #162854 (Add safety section for atomic_load/store) - #163015 (add `minicore::ffi::VaList`) - #163021 (`va_arg`: pass in `TyAndLayout`) - #163036 ([rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature) - #163042 (Remove redundant output from suggestion) - #163046 (Use verbose suggestion for `const _`) - #163050 (Use verbose suggestion for similarly named label suggestion) - #163052 (Use verbose suggestion for wrong primitive type names) - #163055 (Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 20, 2026
…uwer Rollup of 15 pull requests Successful merges: - #162726 (std: fix unix socket address panic on a full sun_path) - #163016 (Don't claim that escaping value is a reference in diagnostics) - #163040 (Tweak "use array's length as const param" suggestion) - #163060 (Point to fields that introduce trait requirements) - #163066 (don't mark `f128` as reliable on AIX) - #162098 (Tweak `Infallible` docs) - #162854 (Add safety section for atomic_load/store) - #163015 (add `minicore::ffi::VaList`) - #163021 (`va_arg`: pass in `TyAndLayout`) - #163036 ([rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature) - #163042 (Remove redundant output from suggestion) - #163046 (Use verbose suggestion for `const _`) - #163050 (Use verbose suggestion for similarly named label suggestion) - #163052 (Use verbose suggestion for wrong primitive type names) - #163055 (Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 21, 2026
…uwer Rollup of 15 pull requests Successful merges: - #162726 (std: fix unix socket address panic on a full sun_path) - #163016 (Don't claim that escaping value is a reference in diagnostics) - #163040 (Tweak "use array's length as const param" suggestion) - #163060 (Point to fields that introduce trait requirements) - #163066 (don't mark `f128` as reliable on AIX) - #162098 (Tweak `Infallible` docs) - #162854 (Add safety section for atomic_load/store) - #163015 (add `minicore::ffi::VaList`) - #163021 (`va_arg`: pass in `TyAndLayout`) - #163036 ([rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature) - #163042 (Remove redundant output from suggestion) - #163046 (Use verbose suggestion for `const _`) - #163050 (Use verbose suggestion for similarly named label suggestion) - #163052 (Use verbose suggestion for wrong primitive type names) - #163055 (Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 21, 2026
…uwer Rollup of 15 pull requests Successful merges: - #162726 (std: fix unix socket address panic on a full sun_path) - #163016 (Don't claim that escaping value is a reference in diagnostics) - #163040 (Tweak "use array's length as const param" suggestion) - #163060 (Point to fields that introduce trait requirements) - #163066 (don't mark `f128` as reliable on AIX) - #162098 (Tweak `Infallible` docs) - #162854 (Add safety section for atomic_load/store) - #163015 (add `minicore::ffi::VaList`) - #163021 (`va_arg`: pass in `TyAndLayout`) - #163036 ([rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature) - #163042 (Remove redundant output from suggestion) - #163046 (Use verbose suggestion for `const _`) - #163050 (Use verbose suggestion for similarly named label suggestion) - #163052 (Use verbose suggestion for wrong primitive type names) - #163055 (Use the full path of `bug_impl` to avoid bogus errors in rust-analyzer)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 21, 2026
Rollup merge of #163021 - folkertdev:va-arg-ty-and-layout, r=adwinwhite `va_arg`: pass in `TyAndLayout` Just a refactor, no functional changes. It is weird I did not spot this before, it cleans up the code a bunch.
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Sep 24, 2026
fix and test `va_arg` on `f128` on `x86` tracking issue: rust-lang#116909 Or well, maybe not fix but clarify. There are no actual behavioral changes, but I do think the new code is more correct. The clang logic for `va_arg` is kind of (weirdly) complicated. `EmitVAArg` looks simple, but the complexity is hiding in the "messing with TypeInfo" bit: https://github.com/llvm/llvm-project/blob/0e2786dcb5b28f754a1144c27e708d1c42676af9/clang/lib/CodeGen/Targets/X86.cpp#L1080-L1101 ```c++ RValue X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const { auto TypeInfo = getContext().getTypeInfoInChars(Ty); CCState State(*const_cast<CGFunctionInfo *>(CGF.CurFnInfo)); ABIArgInfo AI = classifyArgumentType(Ty, State, /*ArgIndex*/ 0); // Empty records are ignored for parameter passing purposes. if (AI.isIgnore()) return Slot.asRValue(); // x86-32 changes the alignment of certain arguments on the stack. // // Just messing with TypeInfo like this works because we never pass // anything indirectly. TypeInfo.Align = CharUnits::fromQuantity( getTypeStackAlignInBytes(Ty, TypeInfo.Align.getQuantity())); return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo, CharUnits::fromQuantity(4), /*AllowHigherAlign*/ true, Slot); } ``` Relevant for us is that it makes an exception for `f128`, for which a higher align (16, instead of the slot size of 4) is used. https://github.com/llvm/llvm-project/blob/0e2786dcb5b28f754a1144c27e708d1c42676af9/clang/lib/CodeGen/Targets/X86.cpp#L575-L583 ```c++ unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty, unsigned Align) const { // Otherwise, if the alignment is less than or equal to the minimum ABI // alignment, just use the default; the backend will handle this. if (Align <= MinABIStackAlignInBytes) return 0; // Use default alignment. if (Ty->isFloat128Type()) return 16; ``` Our code does not have this `TypeInfo` idea, and it's not correct in general to just use `AllowHigherAlign::Yes`. But using it only for `f128` works. We don't need to consider more complicated cases like structs containing `f128` fields. The code here used `is_like_windows` before. I'm not exactly sure why, the behavior is the same for all accepted types, except now `f128`. But windows does not have that type, so its (c-variadic) ABI is just an LLVM fabrication. The x86 code does not seem to make a distinction based on the ABI, so having the same behavior across targets seems best to me. `va_arg` to fetch an `i128` argument is currently broken in clang. `i128` on the target is apparently a clang extension anyway, so kind of low priority. `f128` I only fixed somewhat recently in llvm/llvm-project#218017. r? beetrees or @tgross35 (this may cause a small conflict with rust-lang#163021)
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Sep 25, 2026
fix and test `va_arg` on `f128` on `x86` tracking issue: rust-lang#116909 Or well, maybe not fix but clarify. There are no actual behavioral changes, but I do think the new code is more correct. The clang logic for `va_arg` is kind of (weirdly) complicated. `EmitVAArg` looks simple, but the complexity is hiding in the "messing with TypeInfo" bit: https://github.com/llvm/llvm-project/blob/0e2786dcb5b28f754a1144c27e708d1c42676af9/clang/lib/CodeGen/Targets/X86.cpp#L1080-L1101 ```c++ RValue X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const { auto TypeInfo = getContext().getTypeInfoInChars(Ty); CCState State(*const_cast<CGFunctionInfo *>(CGF.CurFnInfo)); ABIArgInfo AI = classifyArgumentType(Ty, State, /*ArgIndex*/ 0); // Empty records are ignored for parameter passing purposes. if (AI.isIgnore()) return Slot.asRValue(); // x86-32 changes the alignment of certain arguments on the stack. // // Just messing with TypeInfo like this works because we never pass // anything indirectly. TypeInfo.Align = CharUnits::fromQuantity( getTypeStackAlignInBytes(Ty, TypeInfo.Align.getQuantity())); return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo, CharUnits::fromQuantity(4), /*AllowHigherAlign*/ true, Slot); } ``` Relevant for us is that it makes an exception for `f128`, for which a higher align (16, instead of the slot size of 4) is used. https://github.com/llvm/llvm-project/blob/0e2786dcb5b28f754a1144c27e708d1c42676af9/clang/lib/CodeGen/Targets/X86.cpp#L575-L583 ```c++ unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty, unsigned Align) const { // Otherwise, if the alignment is less than or equal to the minimum ABI // alignment, just use the default; the backend will handle this. if (Align <= MinABIStackAlignInBytes) return 0; // Use default alignment. if (Ty->isFloat128Type()) return 16; ``` Our code does not have this `TypeInfo` idea, and it's not correct in general to just use `AllowHigherAlign::Yes`. But using it only for `f128` works. We don't need to consider more complicated cases like structs containing `f128` fields. The code here used `is_like_windows` before. I'm not exactly sure why, the behavior is the same for all accepted types, except now `f128`. But windows does not have that type, so its (c-variadic) ABI is just an LLVM fabrication. The x86 code does not seem to make a distinction based on the ABI, so having the same behavior across targets seems best to me. `va_arg` to fetch an `i128` argument is currently broken in clang. `i128` on the target is apparently a clang extension anyway, so kind of low priority. `f128` I only fixed somewhat recently in llvm/llvm-project#218017. r? beetrees or @tgross35 (this may cause a small conflict with rust-lang#163021)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 25, 2026
Rollup merge of #163037 - folkertdev:x86-vaarg-f128, r=beetrees fix and test `va_arg` on `f128` on `x86` tracking issue: #116909 Or well, maybe not fix but clarify. There are no actual behavioral changes, but I do think the new code is more correct. The clang logic for `va_arg` is kind of (weirdly) complicated. `EmitVAArg` looks simple, but the complexity is hiding in the "messing with TypeInfo" bit: https://github.com/llvm/llvm-project/blob/0e2786dcb5b28f754a1144c27e708d1c42676af9/clang/lib/CodeGen/Targets/X86.cpp#L1080-L1101 ```c++ RValue X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const { auto TypeInfo = getContext().getTypeInfoInChars(Ty); CCState State(*const_cast<CGFunctionInfo *>(CGF.CurFnInfo)); ABIArgInfo AI = classifyArgumentType(Ty, State, /*ArgIndex*/ 0); // Empty records are ignored for parameter passing purposes. if (AI.isIgnore()) return Slot.asRValue(); // x86-32 changes the alignment of certain arguments on the stack. // // Just messing with TypeInfo like this works because we never pass // anything indirectly. TypeInfo.Align = CharUnits::fromQuantity( getTypeStackAlignInBytes(Ty, TypeInfo.Align.getQuantity())); return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*Indirect*/ false, TypeInfo, CharUnits::fromQuantity(4), /*AllowHigherAlign*/ true, Slot); } ``` Relevant for us is that it makes an exception for `f128`, for which a higher align (16, instead of the slot size of 4) is used. https://github.com/llvm/llvm-project/blob/0e2786dcb5b28f754a1144c27e708d1c42676af9/clang/lib/CodeGen/Targets/X86.cpp#L575-L583 ```c++ unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty, unsigned Align) const { // Otherwise, if the alignment is less than or equal to the minimum ABI // alignment, just use the default; the backend will handle this. if (Align <= MinABIStackAlignInBytes) return 0; // Use default alignment. if (Ty->isFloat128Type()) return 16; ``` Our code does not have this `TypeInfo` idea, and it's not correct in general to just use `AllowHigherAlign::Yes`. But using it only for `f128` works. We don't need to consider more complicated cases like structs containing `f128` fields. The code here used `is_like_windows` before. I'm not exactly sure why, the behavior is the same for all accepted types, except now `f128`. But windows does not have that type, so its (c-variadic) ABI is just an LLVM fabrication. The x86 code does not seem to make a distinction based on the ABI, so having the same behavior across targets seems best to me. `va_arg` to fetch an `i128` argument is currently broken in clang. `i128` on the target is apparently a clang extension anyway, so kind of low priority. `f128` I only fixed somewhat recently in llvm/llvm-project#218017. r? beetrees or @tgross35 (this may cause a small conflict with #163021)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Just a refactor, no functional changes. It is weird I did not spot this before, it cleans up the code a bunch.